﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using TeenyGrab.Helpers;

namespace TeenyGrab.Serialization
{
    [Serializable]
    public class SerializableImageFormat : ISerializable
    {
        public ImageFormat Format { get; set; }

        public SerializableImageFormat(SerializationInfo info, StreamingContext context)
        {
            var format = info.GetString("Format");
            Format = format.ToImageFormat();
        }

        public SerializableImageFormat()
        {
            Format = ImageFormat.Png;
        }

        public SerializableImageFormat(ImageFormat format)
        {
            Format = format;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Format", Format.GetExtension());
        }
    }
}
